<?php
namespace app\store\validate;

use think\Validate;

class FosterGoods extends Validate
{

    // 验证规则
    protected $rule = [
        'goods_name' => 'require|min:2|max:255|unique:foster_goods',
        'cat_id_1' => 'require|gt:0',
        'wid' => 'require|gt:0',
        'extra_text' => 'requireCallback:check_require',
        'goods_price' => 'require|float',
        'cost_price' => 'require|float|elt:goods_price|gt:0',
        'buy_max' => 'require|number',
        're_speed' => 'require',
        'day_sy' => 'require|float|gt:0',
        'sy_day' => 'require|number|gt:0',
        'yield' => 'require|float|gt:0',
        'goods_img' => 'require',
        'ship_id' => 'requireIf:pinkage,0',
        'store_count' => 'require|number',
        'sort' => 'require|number',
        'goods_content' => 'require',
        'goods_agreement' => 'require',
    ];
    //错误信息
    protected $message = [
        'goods_name.require' => '商品名称必填',
        'goods_name.min' => '商品名称长度至少2个字符',
        'goods_name.max' => '商品名称长度至多255个字符',
        'goods_name.unique' => '商品名称重复',
        'cat_id_1.require' => '请选择所属分类',
        'cat_id_1.gt' => '请选择所属分类',
        'wid.require' => '请选择收益钱包',
        'wid.gt' => '请选择收益钱包',
        'extra_text.requireCallback'=> '请添加额外收益',
        'goods_price.require' => '商品价格必填',
        'goods_price.float' => '商品价格只能为数字',
        'goods_price.lt' => '商品价格必须小于市场价格',
        'cost_price.require' => '成本价格必填',
        'cost_price.float' => '成本价格只能为数字',
        'cost_price.elt' => '成本价格必须小于等于商品价格',
        'cost_price.gt' => '成本价格必须大于0',
        'buy_max.require' => '限购数量必填',
        'buy_max.number' => '限购数量只能为数字',
        're_speed.require' => '加速释放必填,不需要填写0!',
        'day_sy.require' => '每日收益必填',
        'day_sy.float' => '每日收益只能为数字',
        'day_sy.gt' => '每日收益必须大于0',
        'sy_day.require' => '收益周期必填',
        'sy_day.number' => '收益周期只能为数字',
        'sy_day.gt' => '收益周期必须大于0',
        'yield.require' => '产量必填',
        'yield.float' => '产量只能为数字',
        'yield.gt' => '产量必须大于0',
        'goods_img.require' => '商品主图必须上传',
        'ship_id.requireIf' => '请选择运费模板',
        'store_count.require' => '商品库存必填',
        'store_count.number' => '商品库存只能为数字',
        'sort.require' => '商品排序必填',
        'sort.number' => '商品排序只能为数字',
        'goods_content.require' => '商品详情必填',
        'goods_agreement.require' => '商品协议必填',
    ];
    function check_require($value, $data){
        if ($data['extra_wid']>0){
            return true;
        }
        return false;
    }
}
